<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }
        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }
        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }
        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>套餐管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>套餐管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案号/姓名" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <!--      <template>
                          <el-radio class="radio"></el-radio>
                      </template>-->
                <el-table-column prop="id" label="id" align="center"></el-table-column>
                <el-table-column prop="orderDate" width="200px" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="member_id" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="telphone" label="电话" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center" ></el-table-column>
                <el-table-column label="操作" align="center" width="200px">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger"  @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>

            <!-- 修改弹层 -->
            <div class="add-form">
                <el-dialog title="修改预约" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="源数据" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="id">
                                                <el-input v-model="formData.id"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="预约日期">
                                                <el-input v-model="formData.orderDate"  type="date"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="档案号" prop="member_id">
                                                <el-input v-model="formData.member_id"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="电话">
                                                <el-input v-model="formData.telphone"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="预约类型">
                                                <el-input v-model="formData.orderType"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="预约状态">
                                                <el-input v-model="formData.orderStatus"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible2">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="预约日期" prop="orderDate" >
                                    <el-input v-model="formData.orderDate" type="date" />
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="档案号" prop="member_id" >
                                    <el-input v-model="formData.member_id" placeholder="请输入83-92之间"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="姓名" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="电话">
                                    <el-input v-model="formData.telphone" label="top"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="套餐">
                                    <el-input v-model="formData.setmeal_id" placeholder="请输入13-15之间"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="预约状态">
                                    <el-select v-model="formData.orderStatus">
                                        <el-option label="已预约" value="1"></el-option>
                                        <el-option label="未预约" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="预约类型">
                                    <el-select v-model="formData.orderType">
                                        <el-option label="微信预约" value="1"></el-option>
                                        <el-option label="电话预约" value="2"></el-option>
                                        <el-option label="无线预约" value="1"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible2 = false">取消</el-button>
                        <el-button type="primary" @click="handleAddOrder()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        provide () { // 父组件中通过provide来提供变量，在子组件中通过inject来注入变量
            return {
                reload: this.reload
            }
        },
        data:{
            autoUpload:true,//自动上传
            imageUrl:null,//模型数据，用于上传图片完成后图片预览
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize:10,
                total:100,
                queryString:null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData:[],//添加表单窗口中检查组列表数据
            checkgroupIds:[],//添加表单窗口中检查组复选框对应id
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible2:false,
            search:"",
            searchData:"",
            rules: {//校验规则
                member_id: [{ required: true, message: '项目编码为必填项', trigger: 'blur' }],
                name: [{ required: true, message: '项目名称为必填项', trigger: 'blur' }]
            }
        },

        created() {
            this.findPage();
        },
        methods: {
            reload () {
                this.isReload = false;
                this.$nextTick( () => {
                    this.isReload = true;
                });
            },
            handleDelete(row){
                var d = confirm("是否删除该条记录？");
                var _this = this;
                if (d){
                    axios.post("../xiaotian/deleteOrder.do?id=" + row.id).then((res) => {
                        if(true){
                            console.log(this.formData)
                            _this.findPage();
                        }else{
                            this.$message.error(res.data.message);
                        }
                    });
                }
            },

            handleUpdate(row) {
                //弹出编辑窗口
                this.dialogFormVisible = true;
                //回显数据，发送ajax请求根据ID查询当前检查项数据
                axios.get("../xiaotian/findOrder.do?id=" + row.id).then((res) => {
                    if(true){
                        //进行回显，基于VUE的数据绑定实现
                        this.formData =res.data;
                        console.log(this.formData)

                    }else{
                        //查询失败，弹出提示
                        this.$message.error(res.data.message);
                    }
                });
            },
            //修改
            handleAdd () {
                var _this = this;
                this.dialogFormVisible = true;
                //发送ajax请求，将表单数据（套餐基本信息、检查组ID）提交到后台进行处理
                axios.post("../xiaotian/orderUpdate.do",this.formData).then((res) => {
                    _this.dialogFormVisible = false;
                }).finally(() => {
                    this.findPage();
                });
            },
            handleAddOrder () {
                var _this = this;
                this.$refs['dataAddForm'].validate((valid) => {
                    if(valid){
                        //表单校验通过，可以提交数据
                        axios.post("../xiaotian/orderAdd.do",this.formData).then((res) => {
                            _this.findPage();
                            this.findPage()
                            _this.dialogFormVisible2 = false;
                        }).finally(() => {
                            this.findPage()
                            //不管成功还是失败，都调用分页查询方法
                            //隐藏编辑窗口
                            this.dialogFormVisible2 = false;
                        });
                    }else{
                        //表单校验不通过
                        this.$message.error("表单数据校验失败!");
                        return false;
                    }
                });
            },
            findOrderByPage(){
                //分页参数
                var param = {
                    currentPage:this.pagination.currentPage,//页码
                    pageSize:this.pagination.pageSize,//每页显示的记录数
                    queryString:this.pagination.queryString//查询条件
                };
                //请求后台
                axios.post("/xiaotian/findOrderByPage.do",param).then((response)=> {
                    //为模型数据赋值，基于VUE的双向绑定展示到页面
                    this.dataList = response.data.rows;
                    this.pagination.total = response.data.total;
                });
            },
            findPage(){
                //分页参数
                var param = {
                    currentPage:this.pagination.currentPage,//页码
                    pageSize:this.pagination.pageSize,//每页显示的记录数
                    queryString:this.pagination.queryString//查询条件
                };
                //请求后台
                axios.post("/xiaotian/findPage.do",param).then((response)=> {
                    //为模型数据赋值，基于VUE的双向绑定展示到页面
                    this.dataList = response.data.rows;
                    this.pagination.total = response.data.total;
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
                this.activeName = 'first';
                this.imageUrl = null;
                this.checkgroupIds = [];
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible2 = true;
            },

            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            }
        }
    })
</script>
</html>
